<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/


defined('_JEXEC') or die('Restricted access');

class JobBoardControllerJANotes extends JobBoardController{

    /**
     * Constructor
     */
    function __construct( $default = array() )
    {
        parent::__construct( $default );
        $this->set('name', 'notes');
        $this->set('fullname', JBPREFIX.'notes');
        
        // Register Extra tasks
        $this->registerTask('unstarred', 'starred');
        
     }
        
   
    function starred(){
		
        //JRequest::checkToken() or jexit( 'Invalid Token' );
        $Itemid = JRequest::getVar('Itemid');
        
        $user = &JFactory::getUser();
        if($user->id){
            $task = JRequest::getVar('task', 'starred');
            $model =& $this->getModel(JBPREFIX.'notes');
            if($model->starred($task)){            	
                $msg = JText::_("Items Starred successfully");
            } else {
                JError::raiseWarning(0, "Items Starred unsuccessfully");
            }
            
            $this->setMessage($msg);
            
            //$this->setRedirect('index.php?option='. JBCOMNAME .'&controller='.$model->get('name').'&Itemid='.$Itemid);    
        } else {
            // Redirect to user login
        }
    }
    
    
    function save(){
		//JRequest::checkToken() or jexit( 'Invalid Token' );
        $Itemid = JRequest::getVar('Itemid');
        $user = &JFactory::getUser();
        if($user->id){
            $task = 'starred';
            $model =& $this->getModel(JBPREFIX.'notes');
            if($model->addNote()){            	
                
                if (JRequest::getVar('note_type')=='ja_resumes')
                {
            		$msg = JText::_("Resume note is saved successfully");
                	$this->setRedirect(JRoute::_("index.php?option=com_jajobboard&view=jaresumes&layout=jaview&cid[]=".JRequest::getVar('item_id').'&Itemid='.$Itemid),$msg);
                }
                elseif (JRequest::getVar('note_type')=='ja_jobs')
                {
                	$msg = JText::_("Job note is saved successfully");
                	$this->setRedirect(JRoute::_("index.php?option=com_jajobboard&view=jajobs&layout=jaview&cid[]=".JRequest::getVar('item_id').'&Itemid='.$Itemid),$msg);
                }
            } else {
                JError::raiseWarning(0, "Resume note is saved unsuccessfully");
            }
            
            
        } 
    }
    function ajax_save()
    {
    	$Itemid = JRequest::getVar('Itemid');
        $user = &JFactory::getUser();
        if($user->id){
            $task = 'starred';
            $model =& $this->getModel(JBPREFIX.'notes');
            $result = $model->addNote();
            echo $result;
            exit;
        }
        exit;
    }
}
?>
